﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
namespace Chenxin.Lib.Business.DAL
{
    /// <summary>
    /// 数据访问类t_Intention_BillPayedInfo。
    /// </summary>
    public class t_Intention_BillPayedInfo
    {
        public t_Intention_BillPayedInfo()
        { }
        #region  成员方法

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.Business.Entity.t_Intention_BillPayedInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_Intention_BillPayedInfo(");
            strSql.Append("RecordId,BillId,BillCode,PayedMoney,PayedTo,PayDate,bAppCustody,bCustody,ConfirmEmployeeId,ConfirmEmployee,ConfirmDate,AddTime,AddEmployeeId,AddEmployee,AddDepartId,AddDepart,AddCompanyId,AddCompany,AddCityId,AddCity,UpdateEmployeeId,UpdateEmployee,UpdateTime,Status)");

            strSql.Append(" values (");
            strSql.Append("@RecordId,@BillId,@BillCode,@PayedMoney,@PayedTo,@PayDate,@bAppCustody,@bCustody,@ConfirmEmployeeId,@ConfirmEmployee,@ConfirmDate,@AddTime,@AddEmployeeId,@AddEmployee,@AddDepartId,@AddDepart,@AddCompanyId,@AddCompany,@AddCityId,@AddCity,@UpdateEmployeeId,@UpdateEmployee,@UpdateTime,@Status)");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "BillId", DbType.Guid, model.BillId);
            db.AddInParameter(dbCommand, "BillCode", DbType.AnsiString, model.BillCode);
            db.AddInParameter(dbCommand, "PayedMoney", DbType.Decimal, model.PayedMoney);
            db.AddInParameter(dbCommand, "PayedTo", DbType.Int32, model.PayedTo);
            db.AddInParameter(dbCommand, "PayDate", DbType.DateTime, model.PayDate);
            db.AddInParameter(dbCommand, "bAppCustody", DbType.Boolean, model.bAppCustody);
            db.AddInParameter(dbCommand, "bCustody", DbType.Boolean, model.bCustody);
            db.AddInParameter(dbCommand, "ConfirmEmployeeId", DbType.Guid, model.ConfirmEmployeeId);
            db.AddInParameter(dbCommand, "ConfirmEmployee", DbType.AnsiString, model.ConfirmEmployee);
            db.AddInParameter(dbCommand, "ConfirmDate", DbType.DateTime, model.ConfirmDate);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "AddEmployeeId", DbType.Guid, model.AddEmployeeId);
            db.AddInParameter(dbCommand, "AddEmployee", DbType.AnsiString, model.AddEmployee);
            db.AddInParameter(dbCommand, "AddDepartId", DbType.Guid, model.AddDepartId);
            db.AddInParameter(dbCommand, "AddDepart", DbType.AnsiString, model.AddDepart);
            db.AddInParameter(dbCommand, "AddCompanyId", DbType.Guid, model.AddCompanyId);
            db.AddInParameter(dbCommand, "AddCompany", DbType.AnsiString, model.AddCompany);
            db.AddInParameter(dbCommand, "AddCityId", DbType.Guid, model.AddCityId);
            db.AddInParameter(dbCommand, "AddCity", DbType.AnsiString, model.AddCity);
            db.AddInParameter(dbCommand, "UpdateEmployeeId", DbType.Guid, model.UpdateEmployeeId);
            db.AddInParameter(dbCommand, "UpdateEmployee", DbType.AnsiString, model.UpdateEmployee);
            db.AddInParameter(dbCommand, "UpdateTime", DbType.DateTime, model.UpdateTime);
            db.AddInParameter(dbCommand, "Status", DbType.Int32, model.Status);
            db.ExecuteNonQuery(dbCommand);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.Business.Entity.t_Intention_BillPayedInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_Intention_BillPayedInfo set ");
            strSql.Append("BillId=@BillId,");
            strSql.Append("BillCode=@BillCode,");
            strSql.Append("PayedMoney=@PayedMoney,");
            strSql.Append("PayedTo=@PayedTo,");
            strSql.Append("PayDate=@PayDate,");
            strSql.Append("bAppCustody=@bAppCustody,");
            strSql.Append("bCustody=@bCustody,");
            strSql.Append("ConfirmEmployeeId=@ConfirmEmployeeId,");
            strSql.Append("ConfirmEmployee=@ConfirmEmployee,");
            strSql.Append("ConfirmDate=@ConfirmDate,");
            strSql.Append("AddTime=@AddTime,");
            strSql.Append("AddEmployeeId=@AddEmployeeId,");
            strSql.Append("AddEmployee=@AddEmployee,");
            strSql.Append("AddDepartId=@AddDepartId,");
            strSql.Append("AddDepart=@AddDepart,");
            strSql.Append("AddCompanyId=@AddCompanyId,");
            strSql.Append("AddCompany=@AddCompany,");
            strSql.Append("AddCityId=@AddCityId,");
            strSql.Append("AddCity=@AddCity,");
            strSql.Append("UpdateEmployeeId=@UpdateEmployeeId,");
            strSql.Append("UpdateEmployee=@UpdateEmployee,");
            strSql.Append("UpdateTime=@UpdateTime,");
            strSql.Append("Status=@Status");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "BillId", DbType.Guid, model.BillId);
            db.AddInParameter(dbCommand, "BillCode", DbType.AnsiString, model.BillCode);
            db.AddInParameter(dbCommand, "PayedMoney", DbType.Decimal, model.PayedMoney);
            db.AddInParameter(dbCommand, "PayedTo", DbType.Int32, model.PayedTo);
            db.AddInParameter(dbCommand, "PayDate", DbType.DateTime, model.PayDate);
            db.AddInParameter(dbCommand, "bAppCustody", DbType.Boolean, model.bAppCustody);
            db.AddInParameter(dbCommand, "bCustody", DbType.Boolean, model.bCustody);
            db.AddInParameter(dbCommand, "ConfirmEmployeeId", DbType.Guid, model.ConfirmEmployeeId);
            db.AddInParameter(dbCommand, "ConfirmEmployee", DbType.AnsiString, model.ConfirmEmployee);
            db.AddInParameter(dbCommand, "ConfirmDate", DbType.DateTime, model.ConfirmDate);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "AddEmployeeId", DbType.Guid, model.AddEmployeeId);
            db.AddInParameter(dbCommand, "AddEmployee", DbType.AnsiString, model.AddEmployee);
            db.AddInParameter(dbCommand, "AddDepartId", DbType.Guid, model.AddDepartId);
            db.AddInParameter(dbCommand, "AddDepart", DbType.AnsiString, model.AddDepart);
            db.AddInParameter(dbCommand, "AddCompanyId", DbType.Guid, model.AddCompanyId);
            db.AddInParameter(dbCommand, "AddCompany", DbType.AnsiString, model.AddCompany);
            db.AddInParameter(dbCommand, "AddCityId", DbType.Guid, model.AddCityId);
            db.AddInParameter(dbCommand, "AddCity", DbType.AnsiString, model.AddCity);
            db.AddInParameter(dbCommand, "UpdateEmployeeId", DbType.Guid, model.UpdateEmployeeId);
            db.AddInParameter(dbCommand, "UpdateEmployee", DbType.AnsiString, model.UpdateEmployee);
            db.AddInParameter(dbCommand, "UpdateTime", DbType.DateTime, model.UpdateTime);
            db.AddInParameter(dbCommand, "Status", DbType.Int32, model.Status);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_Intention_BillPayedInfo ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Intention_BillPayedInfo GetModel(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,BillId,BillCode,PayedMoney,PayedTo,PayDate,bAppCustody,bCustody,ConfirmEmployeeId,ConfirmEmployee,ConfirmDate,AddTime,AddEmployeeId,AddEmployee,AddDepartId,AddDepart,AddCompanyId,AddCompany,AddCityId,AddCity,UpdateEmployeeId,UpdateEmployee,UpdateTime,Status from t_Intention_BillPayedInfo ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            Chenxin.Lib.Business.Entity.t_Intention_BillPayedInfo model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,BillId,BillCode,PayedMoney,PayedTo,PayDate,bAppCustody,bCustody,ConfirmEmployeeId,ConfirmEmployee,ConfirmDate,AddTime,AddEmployeeId,AddEmployee,AddDepartId,AddDepart,AddCompanyId,AddCompany,AddCityId,AddCity,UpdateEmployeeId,UpdateEmployee,UpdateTime,Status ");
            strSql.Append(" FROM t_Intention_BillPayedInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("UP_GetRecordByPage");
            db.AddInParameter(dbCommand, "tblName", DbType.AnsiString, "t_Intention_BillPayedInfo");
            db.AddInParameter(dbCommand, "fldName", DbType.AnsiString, "ID");
            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            db.AddInParameter(dbCommand, "IsReCount", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "OrderType", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "strWhere", DbType.AnsiString, strWhere);
            return db.ExecuteDataSet(dbCommand);
        }*/

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public static List<Chenxin.Lib.Business.Entity.t_Intention_BillPayedInfo> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,BillId,BillCode,PayedMoney,PayedTo,PayDate,bAppCustody,bCustody,ConfirmEmployeeId,ConfirmEmployee,ConfirmDate,AddTime,AddEmployeeId,AddEmployee,AddDepartId,AddDepart,AddCompanyId,AddCompany,AddCityId,AddCity,UpdateEmployeeId,UpdateEmployee,UpdateTime,Status ");
            strSql.Append(" FROM t_Intention_BillPayedInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.Business.Entity.t_Intention_BillPayedInfo> list = new List<Chenxin.Lib.Business.Entity.t_Intention_BillPayedInfo>();
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Intention_BillPayedInfo ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Business.Entity.t_Intention_BillPayedInfo model = new Chenxin.Lib.Business.Entity.t_Intention_BillPayedInfo();
            object ojb;
            ojb = dataReader["RecordId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RecordId = new Guid(ojb.ToString());
            }
            ojb = dataReader["BillId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BillId = new Guid(ojb.ToString());
            }
            model.BillCode = dataReader["BillCode"].ToString();
            ojb = dataReader["PayedMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PayedMoney = (decimal)ojb;
            }
            ojb = dataReader["PayedTo"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PayedTo = (int)ojb;
            }
            ojb = dataReader["PayDate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PayDate = (DateTime)ojb;
            }
            ojb = dataReader["bAppCustody"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.bAppCustody = (bool)ojb;
            }
            ojb = dataReader["bCustody"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.bCustody = (bool)ojb;
            }
            ojb = dataReader["ConfirmEmployeeId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ConfirmEmployeeId = new Guid(ojb.ToString());
            }
            model.ConfirmEmployee = dataReader["ConfirmEmployee"].ToString();
            ojb = dataReader["ConfirmDate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ConfirmDate = (DateTime)ojb;
            }
            ojb = dataReader["AddTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddTime = (DateTime)ojb;
            }
            ojb = dataReader["AddEmployeeId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddEmployeeId = new Guid(ojb.ToString());
            }
            model.AddEmployee = dataReader["AddEmployee"].ToString();
            ojb = dataReader["AddDepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddDepartId = new Guid(ojb.ToString());
            }
            model.AddDepart = dataReader["AddDepart"].ToString();
            ojb = dataReader["AddCompanyId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddCompanyId = new Guid(ojb.ToString());
            }
            model.AddCompany = dataReader["AddCompany"].ToString();
            ojb = dataReader["AddCityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddCityId = new Guid(ojb.ToString());
            }
            model.AddCity = dataReader["AddCity"].ToString();
            ojb = dataReader["UpdateEmployeeId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UpdateEmployeeId = new Guid(ojb.ToString());
            }
            model.UpdateEmployee = dataReader["UpdateEmployee"].ToString();
            ojb = dataReader["UpdateTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UpdateTime = (DateTime)ojb;
            }
            ojb = dataReader["Status"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Status = (int)ojb;
            }
            return model;
        }

        //直接执行SQL语句
        public static bool ExecuteSQL(string strSQL)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            int count = db.ExecuteNonQuery(CommandType.Text, strSQL);
            if (count > 0)
                return true;
            else
                return false;
        }

        #endregion  成员方法
    }
}

